package cn.wsalix.weixin.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.anlaser.service.impl.CommonServiceImpl;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;
import cn.wsalix.admin.service.UserService;
import cn.wsalix.weixin.entity.WxMessage;
import cn.wsalix.weixin.form.WxMessageForm;
import cn.wsalix.weixin.repository.WxMessageRepository;
import cn.wsalix.weixin.service.WxMessageService;

@Service("wxMessageService")
@Transactional(readOnly = true)
public class WxMessageServiceImpl extends
		CommonServiceImpl<WxMessageForm, WxMessageRepository, WxMessage> implements
		WxMessageService {
	@Autowired
	private WxMessageRepository wxMessageRepository;
	@Autowired
	private UserService userService;

	@Override
	public WxMessageRepository getRepository() {
		return wxMessageRepository;
	}

	@Override
	public String module() {
		return "weixin/message";
	}

	@Override
	public Map<String, SearchFilter> buildByForm(WxMessageForm form) {
		Map<String, Object> searchParams = new HashMap<String, Object>();
		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
		if (form.getWxConfigId() != null && form.getWxConfigId() != 0) {
			filters.put("wxConfig.id", new SearchFilter("wxConfig.id", Operator.EQ,
					form.getWxConfigId()));
		}
		
		return filters;
	}

	@Override
	public Class<WxMessage> getEntityClazz() {
		return WxMessage.class;
	}

}
